package com.dongbo.recorder.screenrecord.prefrences;

public class PreferencesRepository implements PreferencesDataSource {

    private static PreferencesRepository INSTANCE;

    private PreferencesDataSource mDataSource;

    public PreferencesRepository(PreferencesDataSource dataSource) {
        mDataSource = dataSource;
    }

    /**
     * For MVP-Clean Architecture
     */
    public static PreferencesRepository getInstance(PreferencesDataSource preferencesDataSource) {
        if (INSTANCE == null) {
            INSTANCE = new PreferencesRepository(preferencesDataSource);
        }
        return INSTANCE;
    }

    /**
     * For quick usage
     */
    public static PreferencesRepository getDefaultInstance() {
        return getInstance(PreferencesLocalDataSource.getInstance());
    }

    @Override
    public boolean contains(String key) {
        return mDataSource.contains(key);
    }

    @Override
    public void clear() {
        mDataSource.clear();
    }

    @Override
    public void setString(String key, String value) {
        mDataSource.setString(key, value);
    }

    @Override
    public void setBoolean(String key, boolean value) {
        mDataSource.setBoolean(key, value);
    }

    @Override
    public void setInt(String key, int value) {
        mDataSource.setInt(key, value);
    }

    @Override
    public void setLong(String key, long value) {
        mDataSource.setLong(key, value);
    }

    @Override
    public void setFloat(String key, float value) {
        mDataSource.setFloat(key, value);
    }

    @Override
    public String getString(String key, String defaultValue) {
        return mDataSource.getString(key, defaultValue);
    }

    @Override
    public boolean getBoolean(String key, boolean defaultValue) {
        return mDataSource.getBoolean(key, defaultValue);
    }

    @Override
    public int getInt(String key, int defaultValue) {
        return mDataSource.getInt(key, defaultValue);
    }

    @Override
    public long getLong(String key, long defaultValue) {
        return mDataSource.getLong(key, defaultValue);
    }

    @Override
    public float getFloat(String key, float defaultValue) {
        return mDataSource.getFloat(key, defaultValue);
    }
}

